Question should be explained in title.
I assigned it as ?buying_price?, though not sure if correct name, as you can see I dont know how to do it.
Algo. is pretty basic as I am new to this - so naturally it is based of the introduction algo.
def initialize(context):
context.security = symbol('AAPL')
def handle_data(context, data):
mavg5 = data[context.security].mavg(5)
mavg30 = data[context.security].mavg(30)
current_price = data[context.security].price
?buying_price? = data[...?
cash = context.portfolio.cash
if 1.0275*mavg5 > mavg30 and cash > current_price:
# Need to calculate how many shares we can buy
number_of_shares = int(cash/current_price)
# Place the buy order (positive means buy, negative means sell)
order(context.security, +number_of_shares)
log.info("Buying %s" % (context.security.symbol))
elif current_price > 1.055*mavg5 and mavg5 > mavg30 and current_price > ?buying_price?:
# Sell all of our shares by setting the target position to zero
order_target(context.security, 0)
log.info("Selling %s" % (context.security.symbol))
# You can use the record() method to track any custom signal.
# The record graph tracks up to five different variables.
# Here we record the Apple stock price.
record(stock_price=data[context.security].price)